#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>

using namespace std;
int arr[2000000] = { 0 };
char s[200010];
int main()
{
	int t = 0;
	cin >> t;
	int n = 0;
	int ci = 0;
	while (t--)
	{
		int same = 0;
		int flag = 0;
		cin >> n;
		cin >> s;
		int l = int(s[0]);
		s[n] = '0';
		for ( int i = 1; i < n; i++)
		{
			arr[l * 1000 + int(s[i])]++;
			if (l == int(s[i]) && (int)s[i+1]==l)
			{
				same++;
				arr[l * 1000 + int(s[i])]--;
				if (same > 1)
				{
					flag = 1;
					break;
				}
			}
			else
			{
				same = 0;
				if (arr[l * 1000 + int(s[i])] > 1)
				{
					flag = 1;
					break;
				}
			}
			l = int(s[i]);
		}
		if (flag) cout << "YES" << endl;
		else cout << "NO" << endl;
		l = int(s[0]);
		for (int i = 1; i <= n; i++)
		{
			arr[l * 1000 + int(s[i])]=0;
			l = int(s[i]);
		}
	}
	return 0;
}